package com.ppc.ugo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ppc.ugo.dao.mapper.SwiperMapper;
import com.ppc.ugo.dao.pojo.Swiper;
import com.ppc.ugo.service.SwiperService;
import com.ppc.ugo.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
@Slf4j
public class SwiperServiceImpl implements SwiperService {
    @Resource
    private SwiperMapper swiperMapper;

    @Override
    public Result getSwiperData() {
        LambdaQueryWrapper<Swiper> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Swiper::getImage_src, Swiper::getOpen_type, Swiper::getGoods_id, Swiper::getNavigator_url);

        List<Swiper> swipers = swiperMapper.selectList(queryWrapper);

        return Result.success(swipers);
    }

    @Override
    public void addSwiper(Swiper swiper) {
        swiperMapper.insert(swiper);
        log.info("新增轮播图成功，商品id:{}", swiper.getGoods_id());
    }
}
